package model.expression;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import state.TabState;
import state.TurtleState;

import model.expression.AbstractExpression;
import model.parser.ParserException;

public class VariableExpression extends AbstractExpression {

	public List<AbstractExpression> children;
	TurtleState ts;

	/**
	 * 
	 * @param varVal the string rep of the variable
	 * @param ts     the tabstate this var will belong to
	 * @throws ParserException
	 */
	public VariableExpression(String varVal,TabState ts)throws ParserException {
		if(ts.variables.containsKey(varVal)){
			this.children=ts.variables.get(varVal);
		}else{
			throw new ParserException("Variable "+varVal+" does not exist");
		}
	}




	@Override
	public int evaluate() {
		if (this.children.isEmpty()){
			throw new ParserException("Variable was poorly made");
		}
		return this.children.get(0).evaluate();
	}

}
